package com.example.cloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2配置<br>
 * 官网：http://swagger.io/<br>
 * API访问路径：http://localhost:8080/swagger-ui.html
 *
 * @author tongyufu
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    /**
     * 初始化
     *
     * @return swagger docket对象
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                //指定哪个路径下的类和URL会生成API
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.cloud"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("Spring Boot中使用Swagger2构建RESTful APIs")
                .description("我是描述")
                .termsOfServiceUrl("http://www.zhao.com")
                .contact(new Contact("仝玉甫", "https://my.oschina.net/tongyufu/home", "64205113@163.com"))
                .version("1.0")
                .build();
    }
}
